/*
--------------------------------------------------------------------------------
				Ak-Lib. 
			 Project       	: Ak-Lib
			 Group         	: Ak-Lib R&D Team
			 Author        	: Ocean.Wang
			 Create Date 	: 05-01-2010
--------------------------------------------------------------------------------
Code Name 	:  A.K 	~v~
Description	:  Yet Another Cross-Platform Lib.
Cautions    	:
--------------------------------------------------------------------------------
Change History:
Version		: 0.1
Building 		: 05/01/10
10-05.01 first draft, build, debug and test.
--------------------------------------------------------------------------------
*/
#ifndef	_INC_AK_XML2_
#define	_INC_AK_XML2_

#include "ak_types.h"

#ifdef __cplusplus
extern "C" {
#endif

#define 	_SXML_STACK_MAX_FRAME 	128

struct 	_t_xml_desc;

/* the Attribute Array */
typedef struct{
	int 				attrC;
	char 			** 	attrS;	
}_t_xml_attr;

typedef struct{
	int 				childC;
	struct _t_xml_desc**childS;
}_t_xml_child;

typedef struct _t_xml_desc{
	/* Name */
	char 			* 	name;	
	
	/* Attribute */
	_t_xml_attr		 	attr;	

	/* Children */
	_t_xml_child 		child;

	/* Call Back */
	void * 	(			*	cbSetChild)();
	void * 	(			*	cbSetAttr )();
}_t_xml_desc;


/*
--------------------------------------------------------------------------------
The Xml Parse Frame & Stack.
*/
typedef struct{
	_t_xml_desc  * 	parent;
	void 		 * 	cookie;
}_t_xml_stack_frame;

typedef struct{
	int 				total;
	int 				depth;
	_t_xml_stack_frame* frame;
}_t_xml_stack;

#define _SXML_FRAME_SET_PARENT(pFrame, pParent) \
	do{\
		(pFrame)->parent 	= (_t_xml_desc *)(pParent); \
	}while(0)

#define _SXML_FRAME_GET_PARENT(pFrame, pParent) \
	do{\
		(pParent) = (pFrame)->parent; \
	}while(0)

#define _SXML_FRAME_SET_COOKIE(pFrame, pCookie) \
	do{\
		(pFrame)->cookie	= (void *)(pCookie); \
	}while(0)

#define _SXML_FRAME_GET_COOKIE(pFrame, pCookie) \
	do{\
		(pCookie) = (pFrame)->cookie; \
	}while(0)
	


#define _SXML_STACK_INIT(pStack, pFrame, tFrame, pParent, pCookie)	\
	do{\
		(pStack)->depth = 0;		\
		(pStack)->total = (tFrame);	\
		(pStack)->frame = (pFrame);	\
		_SXML_FRAME_SET_PARENT(pFrame, pParent);\
		_SXML_FRAME_SET_COOKIE(pFrame, pCookie);\
	}while(0)


extern	int 	SXml2Reader_XPath(const char * hFile, const char * hPath);
extern	int 	SXml2Reader_Parse(const char * hFile, _t_xml_stack * pStack);





#ifdef __cplusplus
}
#endif


#endif



